<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="关键字">
          <el-input v-model="queryParam.qry_key" style="width:190px" placeholder="根据日程标题或标签搜索"></el-input>
        </el-form-item>
        <el-form-item label="日程类型">
          <el-select v-model="queryParam.qry_scheduletype" filterable clearable>
            <template v-for="item in codeModel.scheduletypeList">
              <el-option :key="item.code" :label="item.name" :value="item.code" />
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="日程时间">
          <el-date-picker v-model="meettimerange" type="daterange" value-format="yyyy-MM-dd" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="meetTimeChange"> </el-date-picker>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :isDisplayDeleteBatch="false" :isDisplayExport="false">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column prop="dispscheduletype" label="日程类型" width="100px" sortable="custom" sort-by="scheduletype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="name" label="日程标题" min-width="150px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="begintime" label="开始时间" width="170px" sortable="custom" sort-by="begintime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="endtime" label="结束时间" width="170px" sortable="custom" sort-by="endtime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="createon" label="创建时间" width="170px" sortable="custom" sort-by="createon" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="140px" v-slot="scope" fixed="right">
          <el-button type="text" icon="el-icon-edit" @click="openEditDialog('editForm', scope.row.id)">编辑</el-button>
          <el-button type="text" icon="el-icon-delete" @click="doDelete(scope.row.id)">删除</el-button>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" :ownerUser="viewUser" @refresh="doRefresh" @closeAll="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'workSchedule',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '工作日程表-列表查询',
      urlPrefix: '/work/schedule/',
      url: {
        queryCodeList: '/work/schedule/dataCodeList'
      },
      // 筛选参数
      filtersInfo: {
        qry_self: 1
      },
      // 排序参数
      sorterInfo: {
        sidx: 'createon',
        sord: 'desc'
      },
      viewUser: {
        code: '',
        name: '',
        isShare: false,
        isView: false
      },
      meettimerange: '',
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  methods: {
    meetTimeChange(value) {
      if (value == null) {
        this.queryParam.qry_begintime = ''
        this.queryParam.qry_endtime = ''
      } else {
        this.queryParam.qry_begintime = value[0]
        this.queryParam.qry_endtime = value[1]
      }
    }
  },
  created() {
    this.viewUser.code = this.user.code
    this.viewUser.name = this.user.name
  }
}
</script>

<style scoped></style>
